package com.java.simple.study.juc.p5;

/**
 * @author zhoujunlin
 * @date 2022年06月27日 21:39
 * @desc
 */
public class AccountSyncLock implements Account {

    private Integer balance;

    public AccountSyncLock(Integer balance) {
        this.balance = balance;
    }

    @Override
    public synchronized Integer getBalance() {
        return balance;
    }

    @Override
    public synchronized void withdraw(Integer amount) {
        balance -= amount;
    }

    public static void main(String[] args) {
        Account.demo(new AccountSyncLock(10000));
        // 剩余:0 cost:141 ms
    }

}
